/*     */ package com.zimbra.cs.session;
/*     */ 
/*     */ import com.zimbra.common.service.ServiceException;
/*     */ import com.zimbra.common.util.Log;
/*     */ import com.zimbra.common.util.Pair;
/*     */ import com.zimbra.common.util.ZimbraLog;
/*     */ import com.zimbra.cs.mailbox.Folder;
/*     */ import com.zimbra.cs.mailbox.MailItem;
/*     */ import com.zimbra.cs.mailbox.MailItem.Type;
/*     */ import com.zimbra.cs.mailbox.MailItem.UnderlyingData;
/*     */ import com.zimbra.cs.mailbox.Mailbox;
/*     */ import com.zimbra.cs.mailbox.Metadata;
/*     */ import com.zimbra.cs.mailbox.util.TypedIdList;
/*     */ import com.zimbra.cs.mailbox.util.TypedIdList.ItemInfo;
/*     */ import java.io.ByteArrayInputStream;
/*     */ import java.io.ByteArrayOutputStream;
/*     */ import java.io.IOException;
/*     */ import java.io.ObjectInputStream;
/*     */ import java.io.ObjectOutputStream;
/*     */ import java.io.Serializable;
/*     */ import java.util.EnumSet;
/*     */ import java.util.HashMap;
/*     */ import java.util.Iterator;
/*     */ import java.util.LinkedHashMap;
/*     */ import java.util.List;
/*     */ import java.util.Map;
/*     */ import java.util.Map.Entry;
/*     */ import java.util.Set;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public final class PendingModifications
/*     */ {
/*     */   public static final class Change
/*     */   {
/*     */     public static final int NONE = 0;
/*     */     public static final int UNREAD = 1;
/*     */     public static final int TAGS = 2;
/*     */     public static final int FLAGS = 4;
/*     */     public static final int CONFIG = 8;
/*     */     public static final int SIZE = 16;
/*     */     public static final int DATE = 32;
/*     */     public static final int SUBJECT = 64;
/*     */     public static final int IMAP_UID = 128;
/*     */     public static final int FOLDER = 256;
/*     */     public static final int PARENT = 512;
/*     */     public static final int CHILDREN = 1024;
/*     */     public static final int SENDERS = 2048;
/*     */     public static final int NAME = 4096;
/*     */     public static final int COLOR = 8192;
/*     */     public static final int POSITION = 16384;
/*     */     public static final int QUERY = 32768;
/*     */     public static final int CONTENT = 65536;
/*     */     public static final int INVITE = 131072;
/*     */     public static final int URL = 262144;
/*     */     public static final int METADATA = 524288;
/*     */     public static final int VIEW = 1048576;
/*     */     public static final int ACL = 2097152;
/*     */     public static final int CONFLICT = 4194304;
/*     */     public static final int LOCK = 8388608;
/*     */     public static final int SHAREDREM = 16777216;
/*     */     public static final int RETENTION_POLICY = 33554432;
/*     */     public static final int DISABLE_ACTIVESYNC = 67108864;
/*     */     public static final int INTERNAL_ONLY = 268435456;
/*     */     public static final int ALL_FIELDS = -1;
/*     */     public Object what;
/*     */     public int why;
/*     */     public Object preModifyObj;
/*     */     
/*     */     Change(Object thing, int reason, Object preModifyObj)
/*     */     {
/*  86 */       this.what = thing;
/*  87 */       this.why = reason;
/*  88 */       this.preModifyObj = preModifyObj;
/*     */     }
/*     */     
/*     */     public String toString()
/*     */     {
/*  93 */       StringBuilder sb = new StringBuilder();
/*  94 */       if ((this.what instanceof MailItem)) {
/*  95 */         MailItem item = (MailItem)this.what;
/*  96 */         sb.append(item.getType()).append(' ').append(item.getId()).append(":");
/*  97 */       } else if ((this.what instanceof Mailbox)) {
/*  98 */         sb.append("mailbox:");
/*     */       }
/*     */       
/* 101 */       if (this.why == 0) sb.append(" **NONE**");
/* 102 */       if ((this.why & 0x1) != 0) sb.append(" UNREAD");
/* 103 */       if ((this.why & 0x2) != 0) sb.append(" TAGS");
/* 104 */       if ((this.why & 0x4) != 0) sb.append(" FLAGS");
/* 105 */       if ((this.why & 0x8) != 0) sb.append(" CONFIG");
/* 106 */       if ((this.why & 0x10) != 0) sb.append(" SIZE");
/* 107 */       if ((this.why & 0x20) != 0) sb.append(" DATE");
/* 108 */       if ((this.why & 0x40) != 0) sb.append(" SUBJECT");
/* 109 */       if ((this.why & 0x80) != 0) sb.append(" IMAP_UID");
/* 110 */       if ((this.why & 0x100) != 0) sb.append(" FOLDER");
/* 111 */       if ((this.why & 0x200) != 0) sb.append(" PARENT");
/* 112 */       if ((this.why & 0x400) != 0) sb.append(" CHILDREN");
/* 113 */       if ((this.why & 0x800) != 0) sb.append(" SENDERS");
/* 114 */       if ((this.why & 0x1000) != 0) sb.append(" NAME");
/* 115 */       if ((this.why & 0x2000) != 0) sb.append(" COLOR");
/* 116 */       if ((this.why & 0x4000) != 0) sb.append(" POSITION");
/* 117 */       if ((this.why & 0x8000) != 0) sb.append(" QUERY");
/* 118 */       if ((this.why & 0x10000) != 0) sb.append(" CONTENT");
/* 119 */       if ((this.why & 0x20000) != 0) sb.append(" INVITE");
/* 120 */       if ((this.why & 0x40000) != 0) sb.append(" URL");
/* 121 */       if ((this.why & 0x80000) != 0) sb.append(" METADATA");
/* 122 */       if ((this.why & 0x100000) != 0) sb.append(" VIEW");
/* 123 */       if ((this.why & 0x200000) != 0) sb.append(" ACL");
/* 124 */       if ((this.why & 0x400000) != 0) sb.append(" CONFLICT");
/* 125 */       if ((this.why & 0x800000) != 0) sb.append(" LOCK");
/* 126 */       if ((this.why & 0x1000000) != 0) sb.append(" SHAREDREM");
/* 127 */       if ((this.why & 0x2000000) != 0) sb.append(" RETENTION_POLICY");
/* 128 */       if ((this.why & 0x4000000) != 0) sb.append(" DISABLE_ACTIVESYNC");
/* 129 */       if ((this.why & 0x10000000) != 0) { sb.append(" **INTERNAL**");
/*     */       }
/* 131 */       return sb.toString();
/*     */     }
/*     */   }
/*     */   
/*     */   public static final class ModificationKey extends Pair<String, Integer> {
/*     */     public ModificationKey(String accountId, Integer itemId) {
/* 137 */       super(itemId);
/*     */     }
/*     */     
/*     */     public ModificationKey(MailItem item) {
/* 141 */       super(Integer.valueOf(item.getId()));
/*     */     }
/*     */     
/*     */     public ModificationKey(ModificationKey mkey) {
/* 145 */       super(mkey.getItemId());
/*     */     }
/*     */     
/*     */     public String getAccountId() {
/* 149 */       return (String)getFirst();
/*     */     }
/*     */     
/*     */     public Integer getItemId() {
/* 153 */       return (Integer)getSecond();
/*     */     }
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/* 161 */   public Set<MailItem.Type> changedTypes = EnumSet.noneOf(MailItem.Type.class);
/*     */   
/*     */   public LinkedHashMap<ModificationKey, MailItem> created;
/*     */   
/*     */   public Map<ModificationKey, Change> modified;
/*     */   public Map<ModificationKey, Change> deleted;
/*     */   
/*     */   public boolean hasNotifications()
/*     */   {
/* 170 */     return ((this.deleted != null) && (!this.deleted.isEmpty())) || ((this.created != null) && (!this.created.isEmpty())) || ((this.modified != null) && (!this.modified.isEmpty()));
/*     */   }
/*     */   
/*     */ 
/*     */   public int getScaledNotificationCount()
/*     */   {
/* 176 */     int count = 0;
/* 177 */     if (this.deleted != null) count += (this.deleted.size() + 3) / 4;
/* 178 */     if (this.created != null) count += this.created.size();
/* 179 */     if (this.modified != null) count += this.modified.size();
/* 180 */     return count;
/*     */   }
/*     */   
/*     */   public boolean overlapsWithAccount(String acctId) {
/* 184 */     acctId = acctId == null ? null : acctId.toLowerCase();
/* 185 */     if (this.deleted != null) {
/* 186 */       for (ModificationKey mkey : this.deleted.keySet()) {
/* 187 */         if (mkey.getAccountId().equals(acctId))
/* 188 */           return true;
/*     */       }
/*     */     }
/* 191 */     if (this.created != null) {
/* 192 */       for (ModificationKey mkey : this.created.keySet()) {
/* 193 */         if (mkey.getAccountId().equals(acctId))
/* 194 */           return true;
/*     */       }
/*     */     }
/* 197 */     if (this.modified != null) {
/* 198 */       for (ModificationKey mkey : this.modified.keySet()) {
/* 199 */         if (mkey.getAccountId().equals(acctId)) {
/* 200 */           return true;
/*     */         }
/*     */       }
/*     */     }
/* 204 */     return false;
/*     */   }
/*     */   
/*     */   public void recordCreated(MailItem item) {
/* 208 */     if (this.created == null) {
/* 209 */       this.created = new LinkedHashMap();
/*     */     }
/* 211 */     this.changedTypes.add(item.getType());
/* 212 */     this.created.put(new ModificationKey(item), item);
/*     */   }
/*     */   
/*     */   public void recordDeleted(String acctId, int id, MailItem.Type type) {
/* 216 */     if (type != MailItem.Type.UNKNOWN) {
/* 217 */       this.changedTypes.add(type);
/*     */     }
/* 219 */     ModificationKey key = new ModificationKey(acctId, Integer.valueOf(id));
/* 220 */     delete(key, type, null);
/*     */   }
/*     */   
/*     */   public void recordDeleted(String acctId, TypedIdList idlist) {
/* 224 */     this.changedTypes.addAll(idlist.types());
/* 225 */     for (Map.Entry<MailItem.Type, List<TypedIdList.ItemInfo>> entry : idlist) {
/* 226 */       type = (MailItem.Type)entry.getKey();
/* 227 */       for (TypedIdList.ItemInfo iinfo : (List)entry.getValue())
/* 228 */         delete(new ModificationKey(acctId, iinfo.getId()), type, null);
/*     */     }
/*     */     MailItem.Type type;
/*     */   }
/*     */   
/*     */   public void recordDeleted(MailItem itemSnapshot) {
/* 234 */     MailItem.Type type = itemSnapshot.getType();
/* 235 */     this.changedTypes.add(type);
/* 236 */     delete(new ModificationKey(itemSnapshot), type, itemSnapshot);
/*     */   }
/*     */   
/*     */   public void recordDeleted(Map<ModificationKey, Change> deletes) {
/* 240 */     if ((deletes != null) && (!deletes.isEmpty())) {
/* 241 */       for (Map.Entry<ModificationKey, Change> entry : deletes.entrySet()) {
/* 242 */         this.changedTypes.add((MailItem.Type)((Change)entry.getValue()).what);
/* 243 */         delete((ModificationKey)entry.getKey(), (Change)entry.getValue());
/*     */       }
/*     */     }
/*     */   }
/*     */   
/*     */   private void delete(ModificationKey key, MailItem.Type type, MailItem itemSnapshot) {
/* 249 */     delete(key, new Change(type, 0, itemSnapshot));
/*     */   }
/*     */   
/*     */   private void delete(ModificationKey key, Change chg) {
/* 253 */     if ((this.created != null) && (this.created.remove(key) != null)) {
/* 254 */       return;
/*     */     }
/* 256 */     if (this.modified != null) {
/* 257 */       this.modified.remove(key);
/*     */     }
/* 259 */     if (this.deleted == null) {
/* 260 */       this.deleted = new HashMap();
/*     */     }
/* 262 */     Change existingChg = (Change)this.deleted.get(key);
/* 263 */     if (existingChg == null) {
/* 264 */       this.deleted.put(key, chg);
/* 265 */     } else if (existingChg.preModifyObj == null) {
/* 266 */       existingChg.preModifyObj = chg.preModifyObj;
/*     */     }
/*     */   }
/*     */   
/*     */   public void recordModified(ModificationKey mkey, Change chg) {
/* 271 */     recordModified(mkey, chg.what, chg.why, chg.preModifyObj, false);
/*     */   }
/*     */   
/*     */   public void recordModified(Mailbox mbox, int reason)
/*     */   {
/* 276 */     recordModified(new ModificationKey(mbox.getAccountId(), Integer.valueOf(0)), mbox, reason, null, false);
/*     */   }
/*     */   
/*     */   public void recordModified(MailItem item, int reason) {
/* 280 */     this.changedTypes.add(item.getType());
/* 281 */     recordModified(new ModificationKey(item), item, reason, null, true);
/*     */   }
/*     */   
/*     */   public void recordModified(MailItem item, int reason, MailItem preModifyItem) {
/* 285 */     this.changedTypes.add(item.getType());
/* 286 */     recordModified(new ModificationKey(item), item, reason, preModifyItem, false);
/*     */   }
/*     */   
/*     */   private void recordModified(ModificationKey key, Object item, int reason, Object preModifyObj, boolean snapshotItem)
/*     */   {
/* 291 */     Change chg = null;
/* 292 */     if ((this.created != null) && (this.created.containsKey(key))) {
/* 293 */       if ((item instanceof MailItem)) {
/* 294 */         recordCreated((MailItem)item);
/*     */       }
/* 296 */       return; }
/* 297 */     if ((this.deleted != null) && (this.deleted.containsKey(key)))
/* 298 */       return;
/* 299 */     if (this.modified == null) {
/* 300 */       this.modified = new HashMap();
/*     */     } else {
/* 302 */       chg = (Change)this.modified.get(key);
/* 303 */       if (chg != null) {
/* 304 */         chg.what = item;
/* 305 */         chg.why |= reason;
/* 306 */         if (chg.preModifyObj == null) {
/* 307 */           chg.preModifyObj = ((preModifyObj == null) && (snapshotItem) ? snapshotItemIgnoreEx(item) : preModifyObj);
/*     */         }
/*     */       }
/*     */     }
/* 311 */     if (chg == null) {
/* 312 */       chg = new Change(item, reason, (preModifyObj == null) && (snapshotItem) ? snapshotItemIgnoreEx(item) : preModifyObj);
/*     */     }
/*     */     
/* 315 */     this.modified.put(key, chg);
/*     */   }
/*     */   
/*     */   private static Object snapshotItemIgnoreEx(Object item) {
/* 319 */     if ((item instanceof MailItem)) {
/*     */       try {
/* 321 */         return ((MailItem)item).snapshotItem();
/*     */       } catch (ServiceException e) {
/* 323 */         ZimbraLog.mailbox.warn("Error in taking item snapshot", e);
/*     */       }
/*     */     }
/* 326 */     return null;
/*     */   }
/*     */   
/*     */   PendingModifications add(PendingModifications other) {
/* 330 */     this.changedTypes.addAll(other.changedTypes);
/*     */     
/* 332 */     if (other.deleted != null) {
/* 333 */       for (Map.Entry<ModificationKey, Change> entry : other.deleted.entrySet()) {
/* 334 */         delete((ModificationKey)entry.getKey(), (Change)entry.getValue());
/*     */       }
/*     */     }
/*     */     
/* 338 */     if (other.created != null) {
/* 339 */       for (MailItem item : other.created.values()) {
/* 340 */         recordCreated(item);
/*     */       }
/*     */     }
/*     */     
/* 344 */     if (other.modified != null) {
/* 345 */       for (Change chg : other.modified.values()) {
/* 346 */         if ((chg.what instanceof MailItem)) {
/* 347 */           recordModified((MailItem)chg.what, chg.why, (MailItem)chg.preModifyObj);
/* 348 */         } else if ((chg.what instanceof Mailbox)) {
/* 349 */           recordModified((Mailbox)chg.what, chg.why);
/*     */         }
/*     */       }
/*     */     }
/*     */     
/* 354 */     return this;
/*     */   }
/*     */   
/*     */   public void clear() {
/* 358 */     this.created = null;
/* 359 */     this.deleted = null;
/* 360 */     this.modified = null;
/* 361 */     this.changedTypes.clear();
/*     */   }
/*     */   
/*     */   public static final class ModificationKeyMeta implements Serializable
/*     */   {
/*     */     String accountId;
/*     */     Integer itemId;
/*     */     
/*     */     public ModificationKeyMeta(String accountId, int itemId) {
/* 370 */       this.accountId = accountId;
/* 371 */       this.itemId = Integer.valueOf(itemId);
/*     */     }
/*     */   }
/*     */   
/*     */   public static final class ChangeMeta implements Serializable { public ObjectType whatType;
/*     */     public String metaWhat;
/*     */     
/* 378 */     public static enum ObjectType { MAILBOX,  MAILITEM,  MAILITEMTYPE;
/*     */       
/*     */       private ObjectType() {}
/*     */     }
/*     */     
/*     */     public int metaWhy;
/*     */     public ObjectType preModifyObjType;
/*     */     public String metaPreModifyObj;
/*     */     public ChangeMeta(ObjectType type, String thing, int reason, ObjectType preModifyObjType, String preModifyObj) {
/* 387 */       this.whatType = type;
/* 388 */       this.metaWhat = thing;
/* 389 */       this.metaWhy = reason;
/* 390 */       this.preModifyObjType = preModifyObjType;
/* 391 */       this.metaPreModifyObj = preModifyObj;
/*     */     }
/*     */   }
/*     */   
/*     */   private Map<ModificationKeyMeta, ChangeMeta> getSerializable(Map<ModificationKey, Change> map)
/*     */   {
/* 397 */     if (map == null) {
/* 398 */       return null;
/*     */     }
/* 400 */     Map<ModificationKeyMeta, ChangeMeta> ret = new LinkedHashMap();
/* 401 */     Iterator<Map.Entry<ModificationKey, Change>> iter = map.entrySet().iterator();
/* 402 */     while (iter.hasNext()) {
/* 403 */       Map.Entry<ModificationKey, Change> entry = (Map.Entry)iter.next();
/* 404 */       Change change = (Change)entry.getValue();
/*     */       
/*     */ 
/* 407 */       PendingModifications.ChangeMeta.ObjectType metaPreModifyObjType = null;
/* 408 */       String metaPreModifyObj = null;
/* 409 */       String metaWhat; if ((change.what instanceof MailItem)) {
/* 410 */         PendingModifications.ChangeMeta.ObjectType whatType = PendingModifications.ChangeMeta.ObjectType.MAILITEM;
/* 411 */         metaWhat = ((MailItem)change.what).serializeUnderlyingData().toString(); } else { String metaWhat;
/* 412 */         if ((change.what instanceof MailItem.Type)) {
/* 413 */           PendingModifications.ChangeMeta.ObjectType whatType = PendingModifications.ChangeMeta.ObjectType.MAILITEMTYPE;
/* 414 */           metaWhat = ((MailItem.Type)change.what).name(); } else { String metaWhat;
/* 415 */           if ((change.what instanceof Mailbox)) {
/* 416 */             PendingModifications.ChangeMeta.ObjectType whatType = PendingModifications.ChangeMeta.ObjectType.MAILBOX;
/*     */             
/* 418 */             metaWhat = null;
/*     */           } else {
/* 420 */             ZimbraLog.session.warn("Unexpected mailbox change : " + change.what);
/* 421 */             continue; } } }
/*     */       String metaWhat;
/*     */       PendingModifications.ChangeMeta.ObjectType whatType;
/* 424 */       if ((change.preModifyObj instanceof MailItem)) {
/* 425 */         metaPreModifyObjType = PendingModifications.ChangeMeta.ObjectType.MAILITEM;
/* 426 */         metaPreModifyObj = ((MailItem)change.preModifyObj).serializeUnderlyingData().toString();
/* 427 */       } else if ((change.preModifyObj instanceof MailItem.Type)) {
/* 428 */         metaPreModifyObjType = PendingModifications.ChangeMeta.ObjectType.MAILITEMTYPE;
/* 429 */         metaPreModifyObj = ((MailItem.Type)change.preModifyObj).name();
/* 430 */       } else if ((change.preModifyObj instanceof Mailbox)) {
/* 431 */         metaPreModifyObjType = PendingModifications.ChangeMeta.ObjectType.MAILBOX;
/* 432 */         metaPreModifyObj = null;
/*     */       }
/*     */       
/* 435 */       ModificationKeyMeta keyMeta = new ModificationKeyMeta(((ModificationKey)entry.getKey()).getAccountId(), ((ModificationKey)entry.getKey()).getItemId().intValue());
/* 436 */       ChangeMeta changeMeta = new ChangeMeta(whatType, metaWhat, change.why, metaPreModifyObjType, metaPreModifyObj);
/* 437 */       ret.put(keyMeta, changeMeta);
/*     */     }
/* 439 */     return ret;
/*     */   }
/*     */   
/*     */   public byte[] getSerializedBytes() throws IOException
/*     */   {
/* 444 */     LinkedHashMap<ModificationKeyMeta, String> metaCreated = null;
/* 445 */     Map<ModificationKeyMeta, ChangeMeta> metaModified = null;
/* 446 */     Map<ModificationKeyMeta, ChangeMeta> metaDeleted = null;
/*     */     
/* 448 */     if (this.created != null) {
/* 449 */       metaCreated = new LinkedHashMap();
/* 450 */       Iterator<Map.Entry<ModificationKey, MailItem>> iter = this.created.entrySet().iterator();
/* 451 */       while (iter.hasNext()) {
/* 452 */         Map.Entry<ModificationKey, MailItem> entry = (Map.Entry)iter.next();
/* 453 */         ModificationKeyMeta keyMeta = new ModificationKeyMeta(((ModificationKey)entry.getKey()).getAccountId(), ((ModificationKey)entry.getKey()).getItemId().intValue());
/* 454 */         MailItem item = (MailItem)entry.getValue();
/* 455 */         Metadata meta = item.serializeUnderlyingData();
/* 456 */         metaCreated.put(keyMeta, meta.toString());
/*     */       }
/*     */     }
/* 459 */     metaModified = getSerializable(this.modified);
/* 460 */     metaDeleted = getSerializable(this.deleted);
/*     */     
/* 462 */     ByteArrayOutputStream bos = new ByteArrayOutputStream();
/* 463 */     ObjectOutputStream oos = new ObjectOutputStream(bos);
/* 464 */     oos.writeObject(this.changedTypes);
/* 465 */     oos.writeObject(metaCreated);
/* 466 */     oos.writeObject(metaModified);
/* 467 */     oos.writeObject(metaDeleted);
/* 468 */     oos.flush();
/* 469 */     oos.close();
/* 470 */     return bos.toByteArray();
/*     */   }
/*     */   
/*     */   private static Map<ModificationKey, Change> getOriginal(Mailbox mbox, Map<ModificationKeyMeta, ChangeMeta> map) throws ServiceException
/*     */   {
/* 475 */     if (map == null) {
/* 476 */       return null;
/*     */     }
/* 478 */     Map<ModificationKey, Change> ret = new LinkedHashMap();
/* 479 */     Iterator<Map.Entry<ModificationKeyMeta, ChangeMeta>> iter = map.entrySet().iterator();
/* 480 */     while (iter.hasNext()) {
/* 481 */       Map.Entry<ModificationKeyMeta, ChangeMeta> entry = (Map.Entry)iter.next();
/* 482 */       ModificationKey key = new ModificationKey(((ModificationKeyMeta)entry.getKey()).accountId, ((ModificationKeyMeta)entry.getKey()).itemId);
/* 483 */       ChangeMeta changeMeta = (ChangeMeta)entry.getValue();
/* 484 */       Object what = null;
/* 485 */       Object preModifyObj = null;
/* 486 */       if (changeMeta.whatType == PendingModifications.ChangeMeta.ObjectType.MAILITEM) {
/* 487 */         Metadata meta = new Metadata(changeMeta.metaWhat);
/* 488 */         MailItem.UnderlyingData ud = new MailItem.UnderlyingData();
/* 489 */         ud.deserialize(meta);
/* 490 */         what = MailItem.constructItem(mbox, ud, true);
/* 491 */         if ((what instanceof Folder)) {
/* 492 */           Folder folder = (Folder)what;
/* 493 */           folder.setParent(mbox.getFolderById(null, folder.getFolderId()));
/*     */         }
/* 495 */       } else if (changeMeta.whatType == PendingModifications.ChangeMeta.ObjectType.MAILITEMTYPE) {
/* 496 */         what = MailItem.Type.of(changeMeta.metaWhat);
/* 497 */       } else if (changeMeta.whatType == PendingModifications.ChangeMeta.ObjectType.MAILBOX) {
/* 498 */         mbox.refreshMailbox(null);
/* 499 */         what = mbox;
/*     */       } else {
/* 501 */         ZimbraLog.session.warn("Unexpected mailbox change type received : " + changeMeta.whatType);
/* 502 */         continue;
/*     */       }
/*     */       
/* 505 */       if (changeMeta.preModifyObjType == PendingModifications.ChangeMeta.ObjectType.MAILITEM) {
/* 506 */         Metadata meta = new Metadata(changeMeta.metaPreModifyObj);
/* 507 */         MailItem.UnderlyingData ud = new MailItem.UnderlyingData();
/* 508 */         ud.deserialize(meta);
/* 509 */         preModifyObj = MailItem.constructItem(mbox, ud, true);
/* 510 */         if ((preModifyObj instanceof Folder)) {
/* 511 */           Folder folder = (Folder)preModifyObj;
/* 512 */           folder.setParent(mbox.getFolderById(null, folder.getFolderId()));
/*     */         }
/* 514 */       } else if (changeMeta.preModifyObjType == PendingModifications.ChangeMeta.ObjectType.MAILITEMTYPE) {
/* 515 */         preModifyObj = MailItem.Type.of(changeMeta.metaPreModifyObj);
/* 516 */       } else if (changeMeta.whatType == PendingModifications.ChangeMeta.ObjectType.MAILBOX) {
/* 517 */         what = mbox;
/*     */       } else {
/* 519 */         ZimbraLog.session.warn("Unexpected mailbox change type received : " + changeMeta.whatType);
/* 520 */         continue;
/*     */       }
/* 522 */       Change change = new Change(what, changeMeta.metaWhy, preModifyObj);
/* 523 */       ret.put(key, change);
/*     */     }
/* 525 */     return ret;
/*     */   }
/*     */   
/*     */   public static PendingModifications deserialize(Mailbox mbox, byte[] data) throws IOException, ClassNotFoundException, ServiceException
/*     */   {
/* 530 */     ByteArrayInputStream bis = new ByteArrayInputStream(data);
/* 531 */     ObjectInputStream ois = new ObjectInputStream(bis);
/* 532 */     PendingModifications pms = new PendingModifications();
/* 533 */     pms.changedTypes = ((Set)ois.readObject());
/*     */     
/* 535 */     LinkedHashMap<ModificationKeyMeta, String> metaCreated = (LinkedHashMap)ois.readObject();
/* 536 */     if (metaCreated != null) {
/* 537 */       pms.created = new LinkedHashMap();
/* 538 */       Iterator<Map.Entry<ModificationKeyMeta, String>> iter = metaCreated.entrySet().iterator();
/* 539 */       while (iter.hasNext()) {
/* 540 */         Map.Entry<ModificationKeyMeta, String> entry = (Map.Entry)iter.next();
/* 541 */         Metadata meta = new Metadata((String)entry.getValue());
/* 542 */         MailItem.UnderlyingData ud = new MailItem.UnderlyingData();
/* 543 */         ud.deserialize(meta);
/* 544 */         MailItem item = MailItem.constructItem(mbox, ud, true);
/* 545 */         if ((item instanceof Folder)) {
/* 546 */           Folder folder = (Folder)item;
/* 547 */           folder.setParent(mbox.getFolderById(null, folder.getFolderId()));
/*     */         }
/*     */         
/* 550 */         ModificationKey key = new ModificationKey(((ModificationKeyMeta)entry.getKey()).accountId, ((ModificationKeyMeta)entry.getKey()).itemId);
/* 551 */         pms.created.put(key, item);
/*     */       }
/*     */     }
/*     */     
/* 555 */     Map<ModificationKeyMeta, ChangeMeta> metaModified = (Map)ois.readObject();
/* 556 */     pms.modified = getOriginal(mbox, metaModified);
/*     */     
/* 558 */     Map<ModificationKeyMeta, ChangeMeta> metaDeleted = (Map)ois.readObject();
/* 559 */     pms.deleted = getOriginal(mbox, metaDeleted);
/*     */     
/* 561 */     return pms;
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/session/PendingModifications.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */